package com.mallcai.bigdata.ladon.controller.peekdata.form;

import com.mallcai.bigdata.ladon.controller.BaseForm;
import com.mallcai.bigdata.ladon.dpl.entity.peekdata.Peek;
import com.mallcai.bigdata.ladon.dpl.entity.peekdata.PeekField;
import com.mallcai.bigdata.ladon.dpl.entity.peekdata.PeekRule;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * Created by oneape<oneape15@163.com>
 * Created 2019-05-22 17:13.
 * Modify:
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class PeekForm extends BaseForm {
    @NotNull(message = "主键不能为空", groups = {IdCheck.class, EditCheck.class})
    private Long   peekId;   // 取数Id
    @NotNull(message = "模型Id不能为空", groups = {AddCheck.class, EditCheck.class, ModelIdCheck.class, PreviewDataCheck.class, SaveCheck.class})
    private Long   modelId;  // 模型Id
    @NotNull(message = "取数名称不能为空", groups = {AddCheck.class, EditCheck.class})
    private String name;     // 取数实例名称
    @NotNull(message = "取数返回字段不能为空", groups = {AddCheck.class, EditCheck.class})
    private String fields;   // 返回的数据字段名列表, 多个以","隔开

    private List<PeekRule> rules; // 取数规则

    private List<PeekField> fieldList; // 取数字段

    public interface IdCheck {
    }

    public interface AddCheck {
    }

    public interface EditCheck {
    }
    public interface SaveCheck {
    }

    public interface ModelIdCheck {

    }

    public interface PreviewDataCheck {
    }

    public Peek toEntity() {
        Peek p = new Peek();
        BeanUtils.copyProperties(this, p);
        p.setId(peekId);
        return p;
    }
}
